package com.srv.persistence;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.srv.common.SummaryUserField;
import com.srv.common.UserField;
import com.srv.model.SummaryUser;
import com.srv.model.User;
import com.srv.persistence.impl.DBSummaryUserPersistence;
import com.srv.persistence.impl.DBUserPersistence;
import com.srv.util.ObjectField;

import junit.framework.TestCase;

public class SummaryUserPersistenceTestCase extends TestCase {
	private static Log log = LogFactory.getLog(SummaryUserPersistenceTestCase.class);
	
	private ISummaryUserPersistence summaryUserPersistence = new DBSummaryUserPersistence();
	
	private IUserPersistence userPersistence = new DBUserPersistence();
	
	private long pid = 0;
	public void testDBSummaryUserPersistence() throws PersistenceException{
		//test insert
		SummaryUser user = new SummaryUser();
		String name = UUID.randomUUID().toString();
		String updateName = UUID.randomUUID().toString();
		user.userID = name;
		user.password_md5 = "woshinibaba";
		user = summaryUserPersistence.insertSummaryUser(user);
		
		log.debug("debug info============:" + user.pid);
		assertTrue(user.pid > 0);
		
		//test get
		Map<ObjectField, Object> map = new HashMap<ObjectField, Object>();
		map.put(SummaryUserField.USERID, name);
		user = summaryUserPersistence.querySummaryUser(map).get(0);
		log.debug("debug info============:" + user.pid);
		pid = user.pid;
		assertEquals(name, user.userID);
		
		//test update
		map = new HashMap<ObjectField, Object>();
		map.put(SummaryUserField.USERID, updateName);
		boolean result = summaryUserPersistence.updateSummaryUser(this.pid, map);
		assertTrue(result);
		
		//test insertUser
		User uuser = new User();
		uuser.pid = this.pid;
		uuser.city = "武汉";
		uuser = userPersistence.insertUser(uuser);
		assertNotNull(uuser);
		
		//test getUser
		uuser = userPersistence.getUser(uuser.pid);
		assertNotNull(uuser);
		
		//test updateUser
		map = new HashMap<ObjectField, Object>();
		map.put(UserField.CITY, "北京");
		boolean b = userPersistence.updateUser(uuser.pid, map);
		assertTrue(b);
		
	}
	
//	public void testGetSummaryUser() throws PersistenceException{
//		
//	}
//	
//	public void testUpdateSummaryUser() throws PersistenceException{
//		
//	}
	
	
}
